import { defineConfig, Plugin } from 'vite'
import vue from "@vitejs/plugin-vue"
import { copy } from 'fs-extra'

// 自定义插件，蕾仕于copy-webpack-plugin
const copyAssetsPlugin = (inputDir: string, outputDir: string): Plugin => {
  return {
    name: 'copy-assets-plugin',
    closeBundle() {
      return copy(inputDir, outputDir)
    },
  };
}

export default defineConfig({
  plugins: [
    vue(),
    copyAssetsPlugin('./src/lib', 'comptecounter/lib'),
    copyAssetsPlugin('./src/packages', 'comptecounter/packages'),
  ],
  build: {
    emptyOutDir: true,
    outDir: 'comptecounter/dist',
    lib: {
      entry: './src/lib/main.ts',
      name: 'demoLib',
      fileName: 'demo-lib',
      formats:['es','umd']
    },
    rollupOptions: {
      external: ['vue'],
      output: {
        globals: {
          vue: "Vue", //对应exter里的vue， 对于UMD模式导入后，可以使用Vue.xxx
        },
      }
    },
  }
})
